package com.qf.ebook.handler;

import com.qf.ebook.exception.EbookException;
import com.qf.ebook.vo.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class EbookExceptionHandler {


    @ExceptionHandler(EbookException.class)
    public ResultVO ebookException(EbookException ex){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(ex.getCode());
        resultVO.setMsg(ex.getMessage());
        return resultVO;
    }

    /*
    {code:500,msg:"/ by zero",data:null}
     */
    @ExceptionHandler(Exception.class)
    public ResultVO exception(Exception ex){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(500);
        resultVO.setMsg(ex.getMessage());
        return resultVO;
    }
}
